import os
from configparser import ConfigParser
import datetime  # 导入日期时间模块

# 使用相对目录确定文件位置
_conf_dir = os.path.dirname(__file__)
_conf_file = os.path.join(_conf_dir, 'config.ini')

# 项目路径
prj_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))  # 当前文件的上一级的上一级目录（增加一级）
# data_path = os.path.join(prj_path, 'Data')  # 数据目录
data_path = os.path.join(os.path.join(prj_path, 'Data'), "alldata.xlsx")

today = datetime.date.today() #获得今天的日期
tomorrow = today + datetime.timedelta(days=1)

# 继承ConfigParser，写一个将结果转为dict的方法
class MyParser(ConfigParser):
    def as_dict(self):
        d = dict(self._sections)
        for k in d:
            d[k] = dict(d[k])
        return d

# 读取所有配置，以字典方式输出结果
def _get_all_conf():
    _config = MyParser()
    result = {}
    if os.path.isfile(_conf_file):
        try:
            _config.read(_conf_file, encoding='UTF-8')
            result = _config.as_dict()
        except OSError:
            raise ValueError("Read config file failed: %s" % OSError)
    return result

# 将各配置读取出来，放在变量中，后续其它文件直接引用这个这些变量
config = _get_all_conf()
smtp_cfg = config['smtp']
email_cfg = config['email']
log_cfg = config['log']
browser_cfg = config['browser']
browsername_cfg = config['browser']['browsername']


#接口自动化
# Aide3.0-day测试服域名
Aide_host_name = "https://rel.manage.qxdaojia.com/api"
H5_host_name = "https://rel.m.qxdaojia.com/api"

# Aide3.0-day数据库配置
db_host_device_middle = 'rm-wz9f219tjra6937z7.mysql.rds.aliyuncs.com'
db_port_device_middle = 3306
db_user_device_middle = 'fangzhigeng'
db_passwd_device_middle = "qxdaojia#123"
db_ad_middle = 'open_ad'


